KISSY.use("waterfall,ajax,template,node", function(S, Waterfall, io, Template, Node) {
	var $ = Node.all;

	var design_kissy = S.Template($('#design_kissy').html()),
		nextpage = 1,
		waterfall = new Waterfall.Loader({
			container: "#design",
			adjustEffect:{  
              duration:0.5,  
              easing:"easeInStrong"  
            },  
            diff :10,
			load: function(success, end) {
				S.ajax({
					type: 'post',
					data: {
						'page': nextpage,
						'pageSize': 8,  
						'format': 'json'
					},
					url: 'deal_collection.do',
					dataType: "json",
					success: function(d) {
						// 如果数据错误, 则立即结束 
						if (d['stat'] !== 'ok') {
							alert('load data error!');
							end();
							return;
						}
						// 如果到最后一页了, 也结束加载 
						nextpage = d.property.pageSize + 1;

						if (nextpage > d.property.pageCount) {

						if (nextpage > d.property.pages) {

							end();
							return;
						}
						// 拼装每页数据 
						var items = [];
						S.each(d, function(item) {  
							items.push(design_kissy.render(item));
						});
						success(items);
					},
					complete: function() {
					}
				});
			},
			// align:'left', // center (default), right 
			minColCount: 2,
			colWidth: 225,
			align:"justify"
		});
	waterfall.on('adjustComplete', function() {
		S.log('after adjust complete!');
	});
	waterfall.on('addComplete', function() {
		S.log('after add complete!');
	});
	// scrollTo 
	$('#BackToTop').on('click', function(e) {
		e.halt();
		e.preventDefault();
		$(window).stop();
		$(window).animate({
			scrollTop: 0
		}, 1, "easeOut");
	});
});